﻿using System.Collections;
using System.Collections.Generic;
using Pb;
using UnityEngine;

public class EmailItem : MonoBehaviour {

    public GameObject ItemBtn;
    //public GameObject ReadStatus;
    public GameObject HaveReadIcon;
    public GameObject NotReadIcon;
    public string contentStr;
    public string time;
    public UILabel EmailItemContent;
    public int id;
    public bool isRead;
    // Use this for initialization
    private void Awake()
    {
        UIEventListener.Get(ItemBtn).onClick = EmailItemBtnClick;       
    }
    /// <summary>
    /// Email Item 点击后触发到另一个界面 发送已读邮件消息
    /// </summary>
    /// <param name="Button"></param>
    public void EmailItemBtnClick(GameObject Button)
    {
        Debug.Log(Button.name);
        //发送已读邮件消息
        //send
        if (!isRead)
        {            
            SendReadMsg();
            //当前Item 红点隐藏
            //ReadStatus.SetActive(false);            
            HaveReadIcon.SetActive(true);
            NotReadIcon.SetActive(false);
        }        
        //UIPanel_ScrollView 
        GameObject UIPanel_ScrollView = GameObject.Find("UIScrollView");
        UIPanel_ScrollView.SetActive(false);

        GameObject Email = NGUITools.AddChild(GameObject.Find("E_MailPanel").gameObject, (GameObject)(Resources.Load("GameHall/E_Mail/Content")));

        string newtime = time.Split(' ')[0].Replace('-', '/');
        Email.GetComponent<EmailAllText>().LoadMsg(UIPanel_ScrollView, contentStr, newtime);

    }
    void SendReadMsg()
    {
        AuthMessageReadRequest MR = new Pb.AuthMessageReadRequest { MsgId = id };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(MR, MsgId.AuthMessageReadRequest);
    }
}
